package com.ruoyi.web.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.client.MesClientConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IMesClientConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 页面配置Controller
 *
 * @author ruoyi
 * @date 2023-02-21
 */
@Api(value = "MesClientConfigController", tags = "页面配置API")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/client/MesClientConfig" )
public class MesClientConfigController extends BaseController {

    private final IMesClientConfigService iMesClientConfigService;

    /**
     * 查询页面配置列表
     */
    @ApiOperation(value = "查询页面配置列表")
    @GetMapping("/list")
    public TableDataInfo list(MesClientConfig mesClientConfig)
    {
        startPage();
        LambdaQueryWrapper<MesClientConfig> lqw = new LambdaQueryWrapper<MesClientConfig>();
        if (mesClientConfig.getPageId() != null){
            lqw.eq(MesClientConfig::getPageId ,mesClientConfig.getPageId());
        }
        if (StringUtils.isNotBlank(mesClientConfig.getStatus())){
            lqw.eq(MesClientConfig::getStatus ,mesClientConfig.getStatus());
        }
        if (mesClientConfig.getUsageId() != null){
            lqw.eq(MesClientConfig::getUsageId ,mesClientConfig.getUsageId());
        }
        if (mesClientConfig.getLoadTime() != null){
            lqw.eq(MesClientConfig::getLoadTime ,mesClientConfig.getLoadTime());
        }
        if (mesClientConfig.getQualityGroupId() != null){
            lqw.eq(MesClientConfig::getQualityGroupId ,mesClientConfig.getQualityGroupId());
        }
        if (mesClientConfig.getPageRelationId() != null){
            lqw.eq(MesClientConfig::getPageRelationId ,mesClientConfig.getPageRelationId());
        }
        if (StringUtils.isNotBlank(mesClientConfig.getEquipmentCode())){
            lqw.eq(MesClientConfig::getEquipmentCode ,mesClientConfig.getEquipmentCode());
        }
        if (StringUtils.isNotBlank(mesClientConfig.getPageNickName())){
            lqw.eq(MesClientConfig::getPageNickName ,mesClientConfig.getPageNickName());
        }
        List<MesClientConfig> list = iMesClientConfigService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出页面配置列表
     */
    @Log(title = "页面配置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesClientConfig mesClientConfig) {
        LambdaQueryWrapper<MesClientConfig> lqw = new LambdaQueryWrapper<MesClientConfig>(mesClientConfig);
        List<MesClientConfig> list = iMesClientConfigService.list(lqw);
        ExcelUtil<MesClientConfig> util = new ExcelUtil<MesClientConfig>(MesClientConfig. class);
        return util.exportExcel(list, "config" );
    }

    /**
     * 获取页面配置详细信息
     */
    @ApiOperation(value = "获取页面配置详细信息")
    @GetMapping(value = "/{configId}" )
    public AjaxResult getInfo(@PathVariable("configId" ) Long configId) {
        return AjaxResult.success(iMesClientConfigService.getById(configId));
    }

    /**
     * 新增页面配置
     */
    @ApiOperation(value = "新增页面配置")
    @Log(title = "页面配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesClientConfig mesClientConfig) {
        return toAjax(iMesClientConfigService.save(mesClientConfig) ? 1 : 0);
    }

    /**
     * 修改页面配置
     */
    @ApiOperation(value = "修改页面配置")
    @Log(title = "页面配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesClientConfig mesClientConfig) {
        return toAjax(iMesClientConfigService.updateById(mesClientConfig) ? 1 : 0);
    }

    /**
     * 删除页面配置
     */
    @ApiOperation(value = "删除页面配置")
    @Log(title = "页面配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}" )
    public AjaxResult remove(@PathVariable Long[] configIds) {
        return toAjax(iMesClientConfigService.removeByIds(Arrays.asList(configIds)) ? 1 : 0);
    }
}
